package com.mef.smsplat.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mef.smsplat.dao.PersonInfoDao;
import com.mef.smsplat.dao.base.DataGridModel;
import com.mef.smsplat.dao.base.EntityDao;
import com.mef.smsplat.dao.base.Page;
import com.mef.smsplat.domain.PersonInfoDomain;
import com.mef.smsplat.service.base.BaseService;

@Service
@Transactional
public class PersonInfoService extends BaseService<PersonInfoDomain, String> {
	
	private PersonInfoDao personInfoDao;
	
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setPersonInfoDao(PersonInfoDao personInfoDao) {
		this.personInfoDao =personInfoDao;
	}
	@Override
	public EntityDao getEntityDao() {
		return this.personInfoDao;
	}
	
	/**
	 * 分页查询
	 * @param personName
	 * @param personNi
	 * @param personPhone
	 * @param dgm
	 * @return
	 */
	@Transactional(readOnly=true)
	public Page<PersonInfoDomain> query(String personName,String personNi,String personPhone,String groupId,DataGridModel dgm){
		Page<PersonInfoDomain> page = personInfoDao.query(personName, personNi, personPhone,groupId, dgm);
		//以后可能会用到
//		List<PersonInfoDomain> list =  page.getRows();
//		for(PersonInfoDomain person:list){
//			
//		}
		return page;
	}
	
	/**
	 * 查询身份证号是否唯一
	 * @param personPhone
	 * @param id
	 * @return
	 */
	@Transactional(readOnly=true)
	public boolean isUnique(String personPhone, String id){
		boolean isUnique = personInfoDao.queryByPhoneAndId(personPhone, id);
		return isUnique;
	}
	
	/**
	 * 删除组关联里面的记录
	 * @param ids
	 */
	@Transactional
	public void deleteRelateGroup(String[] ids){
		personInfoDao.deletePersonMember(ids);
	}
}
